﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using QQ.Util;
using RTGather.Lib;
using System.Text.RegularExpressions;
using RuoTeng.Util;
using System.IO;

namespace QQ.Util
{
    public static class TextBoxTools

    {

        /// <summary>
        /// 获取text每行数据并放在list里面
        /// </summary>
        /// <param name="tx"></param>
        /// <returns></returns>
        public static List<string> getTextBoxList(TextBox tx)
        {

            List<string> list = new List<string>();
            foreach (string str in tx.Lines)
            {
                if (str.Trim() != "")
                {
                    list.Add(str);
                }
            } 
            return list; 
        }


        /// <summary>
        /// 获取url列表并组装
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public static List<Gather> getGathers(List<string> list)
        {
            List<Gather> gatherlist = new List<Gather>();
            if (list.Count > 0)
            {
                foreach (string str in list)
                {
                    string[] resultString = Regex.Split(str, "-----", RegexOptions.IgnoreCase);
                    if (resultString.Length == 3)
                    {
                        Gather g = new Gather();
                        g.Name = resultString[0];
                        g.Count = ParseType.ParseInt(resultString[1]);
                        g.Url = resultString[2];
                        gatherlist.Add(g);
                    }
                } 
            }
            return gatherlist;
        }

       


        public static List<string> getFileList(string filename)
        {

            List<string> list = new List<string>();
            try
            {
                System.IO.StreamReader reader = new System.IO.StreamReader(filename);
                string line = "";
                while ((line = reader.ReadLine()) != null)
                {
                    
                    line = line.Trim();
                    if (line != ""   && !list.Contains(line))
                    {
                        list.Add(line);
                    }
                }
                reader.Close();
            }
            catch { }
            return list;
        } 

    }
}
